package com.shujia.spark.core

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD

object Demo4Filter {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName("map")
    conf.setMaster("local")

    val sc = new SparkContext(conf)


    //读取学生表的数据
    val studentsRDD: RDD[String] = sc.textFile("data/students.txt")

    /**
     * Filter:将RDD的数据一条一条传递给函数，如果函数返回true保留数据，如果函数返回false过滤数据
     *
     * filter会减少RDD的数据行数
     *
     */

    val filterRDD: RDD[String] = studentsRDD.filter((student: String) => {
      val gender: String = student.split(",")(3)

      "男".equals(gender)
    })

    filterRDD.foreach(println)

  }

}
